<template>
    <!--我的课程-->
    <div class="class-contain">
        <div class="nav-title">
            <div class="title">我的课程</div>
        </div>
        <ul class="classes-content">
            <li class="classesItem" v-for="(course,index) in courseList" :key="index">
                <div class="imgWrap">
                    <div class="foldbtn"
                         v-if="course.course_type==1"
                         @click="handleOpenCourse(course)"
                    >展开课程</div>
                    <div class="foldbtn"
                         v-if="course.course_type==2"
                         @click="handleOpenCalendar(course)"
                    >查看课表</div>
                </div>
                <div class="intro-box">
                    <p class="intro-name">
                        <span class="name">{{course.course_name}}</span>
                        <span class="tag" v-if="course.course_type==1">网课</span>
                        <span class="tag" v-if="course.course_type==2">直播</span>
                    </p>
                    <div class="intro-inline">
                        <div class="energy-box">
                            <div class="energy-bar" :style="{width:course.sec_lab_id+ '%'}"></div>
                        </div>
                        <p>学习进度{{course.sec_lab_id}}%</p>
                    </div>
                    <div>
                        <p>共 32 课时  已学 8 课时</p>
                    </div>
                </div>
            </li>
        </ul>
        <transition name="popup">
        <!--展开课程-->
        <div class="popup course-pop" v-if="pageStatus">
            <div class="body">
                <div class="close" @click="handleCloseCourse"></div>
                <div class="title">
                    全部课程
                </div>
                <div class="popup-contain">
                    <courseCatalog :courseId="activeCourse.id" :setting="settings"></courseCatalog>
                </div>
            </div>
        </div>
        </transition>
        <transition name="popup">
        <!--查看课表-->
        <div class="popup course-pop" v-if="liveStatus">
            <div class="body">
                <div class="close" @click="handleCloseCalendar"></div>
                <div class="title">
                    直播课程表
                </div>
                <div class="popup-contain">
                    <courseCalendar :courseId="activeLive.id"></courseCalendar>
                </div>
            </div>
        </div>
        </transition>
    </div>
</template>
<script>
    import courseCatalog from '../comp/courseCatalog.vue'
    import courseCalendar from '../comp/courseCalendar.vue'
export default {
    name: 'userClassOverview',
    components: {
        courseCatalog,
        courseCalendar
    },
    data() {
        return {
            activeCourse: null,
            activeLive: null,
            courseList: [],
            pageStatus: false,
            liveStatus: false,
            settings: {
                class: 'overview',
                energy: true,
                video: true,
                startLearn: true,
                download: true
            }
        };
    },
    watch: {
    },
    mounted() {
        this.initCourseList();
    },
    methods: {
        // 初始用户课程
        initCourseList(){
            this.$api.ajaxData({
                pathName: 'getCourseList',
                authorization: true
            }).then(res =>{
                this.courseList = res.obj;
            });
        },
        // 打开章弹窗
        handleOpenCourse(course) {
            this.pageStatus = true;
            this.activeCourse = course;
        },
        // 关闭章弹窗
        handleCloseCourse() {
            this.pageStatus = false;
        },
        // 查看课程表
        handleOpenCalendar(course) {
            this.liveStatus = true;
            this.activeLive = course;
        },
        // 关闭直播弹窗
        handleCloseCalendar() {
            this.liveStatus = false;
        },
    }
};
</script>
<style scoped lang="scss">
.class-contain {
    border: 1px solid #f7f7f7;
    background: #fff;
    .nav-title {
        display: flex;
        flex-wrap: wrap;
        padding: 0 20px;
        line-height: 58px;
        border-bottom: 1px solid #f7f7f7;
        .title {
            margin-right: 20px;
            color: #333;
            font-weight: bold;
        }
        a {
            width: 85px;
            text-align: center;
            color: #666;
            &.active {
                color: #006ade;
                border-bottom: 2px solid #006ade;
            }
        }
    }
    .classes-content {
        padding: 0 20px;
        .classesItem {
            display: flex;
            padding: 20px 0;
            border-bottom: 1px solid #f7f7f7;
            .imgWrap {
                position: relative;
                width: 124px;
                height: 87px;
                margin-right: 20px;
                background: url("../../../assets/image/sucai/u2076.jpg") no-repeat;
                background-size: cover;
                &:before {
                    content: '';
                    position: absolute;
                    top: 0;
                    left: 0;
                    display: block;
                    width: 100%;
                    height: 100%;
                    background: rgba(220,220,220,0.5);
                }
                .foldbtn {
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    display: block;
                    width: 90px;
                    height: 30px;
                    margin-top: -15px;
                    margin-left: -45px;
                    line-height: 30px;
                    border-radius: 15px;
                    font-size: 13px;
                    font-weight: bold;
                    color: #006ade;
                    background: #fff;
                    text-align: center;
                    cursor: pointer;
                }
            }
            &:last-child {
                border: none;
            }
            .intro-box {
                flex: 1;
                .intro-name {
                    .name {
                        display: inline-block;
                        width: 200px;
                    }
                    .tag {
                        display: inline-block;
                        width: 60px;
                        height: 22px;
                        line-height: 20px;
                        border-radius: 11px;
                        color: #006ade;
                        border: 1px solid #006ade;
                        text-align: center;
                    }
                }
                .intro-inline {
                    display: flex;
                    align-items: center;
                    p {
                        margin: 0 0 0 20px;
                    }
                }

            }
        }
    }
}
.energy-box{
    display: block;
    width: 80%;
    height: 6px;
    border-radius: 3px;
    background: rgba(204,204,204,1);
    .energy-bar {
        height: 6px;
        min-width: 1%;
        border-radius: 3px;
        background: #006ade;
    }
}
.popup {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    .body {
        position: relative;
        .close {
            position: absolute;
            top: 21px;
            right: 30px;
            width: 22px;
            height: 22px;
            background: url("../../../assets/image/icon/u2148.png") no-repeat;
            background-size: cover;
        }
        .title {
            display: flex;
            width: 890px;
            height: 64px;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
            background: #006ade;
            font-size: 16px;
            font-weight: bold;
            color: #fff;
            align-items: center;
            text-align: center;
            justify-content: center;
        }
        .popup-contain {
            height: 500px;
            overflow: auto;
            background: #fff;
            font-size: 13px;
            color: #333;
            ul,li,p {
                margin: 0;
            }
            .course-page {
                border-bottom: 1px solid #f7f7f7;
                .page {
                    display: flex;
                    height: 50px;
                    padding: 0 20px;
                    align-items: center;
                    .fold-arrow {
                        @include triangle(12px, #ccc, right);
                        cursor: pointer;
                        transition-duration: 200ms;
                        &.active {
                           transform: rotate(90deg);
                        }
                    }
                    .page-name {
                        flex: 1;
                        margin: 0 10px;
                    }
                    .progress-box {
                        display: flex;
                        width: 300px;
                        align-items: center;
                        span {
                            margin: 0 0 0 10px;
                            color: #a1a1a1;
                        }
                    }
                }
                .page-item-list {
                    li {
                        display: flex;
                        align-items: center;
                        height: 50px;
                        padding: 0 40px;
                        border-top: 1px solid #f7f7f7;
                        .item-name {
                            flex: 1;
                        }
                        .progress-box {
                            display: flex;
                            align-items: center;
                            width: 300px;
                            span {
                                margin: 0 0 0 10px;
                                color: #a1a1a1;
                            }
                        }
                        .icon-video {
                            display: block;
                            width: 15px;
                            height: 15px;
                            margin-left: 15px;
                            background: url("../../../assets/image/icon/u2129.png") no-repeat;
                            background-size: cover;
                        }
                    }
                }
            }
        }
    }
}
</style>
